﻿using System.Collections.Generic;

namespace Sidvall.Data
{
	public class DataRowProvider<TEntity> : IDataRowProvider, IDataRowProvider<TEntity>
	{
		#region Public Members

		#region Items

		private List<TEntity> _Items;
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
		public List<TEntity> Items
		{
			get
			{
				if (_Items == null)
					_Items = new List<TEntity>();
				return _Items;
			}
			protected set
			{
				_Items = value;
			}
		}

		#endregion

		#region Add

		public void Add(TEntity item)
		{
			this.Items.Add(item);
		}

		#endregion
		#region AddRange

		public void AddRange(IEnumerable<TEntity> items)
		{
			this.Items.AddRange(items);
		}

		#endregion
		#region Remove

		public bool Remove(TEntity item)
		{
			return this.Items.Remove(item);
		}

		#endregion
		#region RemoveAt

		public void RemoveAt(int index)
		{
			this.Items.RemoveAt(index);
		}

		#endregion

		#region Interface Members

		System.Collections.IEnumerable IDataRowProvider.DataItems
		{
			get
			{
				return this.Items;
			}
		}
		IEnumerable<TEntity> IDataRowProvider<TEntity>.DataItems
		{
			get
			{
				return this.Items;
			}
		}

		#endregion

		#endregion
		#region Constructors

		public DataRowProvider()
		{
		}
		public DataRowProvider(IEnumerable<TEntity> items)
		{
			if (items == null)
				return;
			this.Items = new List<TEntity>(items);
		}

		#endregion
	}
}
